import React from 'react'
import iconList from '../component/navLeft/iconList.tsx'

export interface MenuItemFromData {
  key: string
  icon?: string
  label: string
  children?: Array<MenuItemFromData>
}

export interface MenuItem {
  key: string
  icon?: React.ReactNode
  label: string
  children?: Array<MenuItem>
}

const convertToMenuItem = (data: Array<MenuItemFromData>): Array<MenuItem> => {
  return data.map((item: MenuItemFromData): MenuItem => {
    return {
      key: item.key,
      icon: item.icon ? iconList[item.icon] : undefined,
      label: item.label,
      children: item.children ? convertToMenuItem(item.children) : undefined,
    }
  })
}

export { convertToMenuItem }
